package com.lvmama.pangolin.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lvmama.pangolin.mybatis.mapper.ConvertTaskMapper;
import com.lvmama.pangolin.mybatis.mapper.qnr.QNRTicketCommodityDetailMapper;
import com.lvmama.pangolin.mybatis.mapper.qnr.QNRTicketCommodityMapper;
import com.lvmama.pangolin.mybatis.mapper.tc.TCTicketCommodityDetailMapper;
import com.lvmama.pangolin.mybatis.mapper.tc.TCTicketCommodityMapper;
import com.lvmama.pangolin.mybatis.mapper.tn.TNTicketCommodityDetailMapper;
import com.lvmama.pangolin.mybatis.mapper.tn.TNTicketCommodityMapper;
import com.lvmama.pangolin.mybatis.mapper.xc.XCTicketCommodityDetailMapper;
import com.lvmama.pangolin.mybatis.mapper.xc.XCTicketCommodityMapper;
import com.lvmama.pangolin.service.PreviousDataService;
@Transactional
@Service
public class PreviousDataServiceImpl implements PreviousDataService{
	private static final Logger logger = Logger.getLogger(PreviousDataServiceImpl.class);
	@Autowired
	private QNRTicketCommodityMapper qnrTicketCommodityMapper;
	@Autowired
	private TNTicketCommodityMapper tnTicketCommodityMapper;
	@Autowired
	private XCTicketCommodityMapper xcTicketCommodityMapper;
	@Autowired
	private TCTicketCommodityMapper tcTicketCommodityMapper;
	@Autowired
	private QNRTicketCommodityDetailMapper qnrTicketCommodityDetailMapper;
	@Autowired
	private TNTicketCommodityDetailMapper tnTicketCommodityDetailMapper;
	@Autowired
	private XCTicketCommodityDetailMapper xcTicketCommodityDetailMapper;
	@Autowired
	private TCTicketCommodityDetailMapper tcTicketCommodityDetailMapper;
	@Autowired
	private ConvertTaskMapper convertTaskMapper;
	@Override
	public int deletePreviousData(int limit) {
		try {
			//保留最近{#limit}个批次的数据，删除老数据
			qnrTicketCommodityMapper.deletePreviousData(limit);
			qnrTicketCommodityDetailMapper.deletePreviousData(limit);
			tnTicketCommodityMapper.deletePreviousData(limit);
			tnTicketCommodityDetailMapper.deletePreviousData(limit);
			xcTicketCommodityMapper.deletePreviousData(limit);
			xcTicketCommodityDetailMapper.deletePreviousData(limit);
			tcTicketCommodityMapper.deletePreviousData(limit);
			tcTicketCommodityDetailMapper.deletePreviousData(limit);
			logger.info("成功删除历史批次数据！");
		} catch (Exception e) {
			logger.error("定时任务删除老批次数据异常");
		}
		return 0;
	}
	
	@Override
	public int deleteConvertPreviousData(int limit) {
		try {
			//保留最近{#limit}个批次的数据，删除老数据
			convertTaskMapper.deletePreviousData(limit);
			logger.info("成功删除历史批次数据！");
		} catch (Exception e) {
			logger.error("定时任务删除老批次数据异常");
		}
		return 0;
	}

}
